/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:22:58 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class DekiemtraDAL : SqlProvider<DekiemtraEntity>
    {
        static DekiemtraDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                DekiemtraEntity entity = new DekiemtraEntity();
				entity.PK_iDekiemtraID = Int64.Parse("0"+dr["PK_iDekiemtraID"].ToString());
				entity.sTendekiemtra = dr["sTendekiemtra"].ToString();
				entity.sGhichu = dr["sGhichu"].ToString();
				entity.dNgaytao =String.IsNullOrEmpty(dr["dNgaytao"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgaytao"].ToString());
				entity.dNgaycapnhat =String.IsNullOrEmpty(dr["dNgaycapnhat"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgaycapnhat"].ToString());
				entity.FK_iNguoitaoID = Int64.Parse("0"+dr["FK_iNguoitaoID"].ToString());
				entity.FK_iNguoicapnhatID = Int64.Parse("0"+dr["FK_iNguoicapnhatID"].ToString());
				entity.FK_iHinhthuckiemtraID = Int16.Parse("0"+dr["FK_iHinhthuckiemtraID"].ToString());
                return entity;
            };
        }
        public static DekiemtraEntity GetOne(Int64 PK_iDekiemtraID)
        {
            string cmdName = "spDekiemtra_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iDekiemtraID", PK_iDekiemtraID);
            DekiemtraEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<DekiemtraEntity> GetAll()
        {
            string cmdName = "spDekiemtra_Get";
            return GetList(cmdName);
        }
        public static List<DekiemtraEntity> GetByFK_iNguoitaoID(Int64 FK_iNguoitaoID)
		{
			string cmdName = "spDekiemtra_GetByFK_FK_iNguoitaoID";
			SqlParameter p = new SqlParameter("@FK_iNguoitaoID",FK_iNguoitaoID);
			List<DekiemtraEntity> list = GetList(cmdName, p);
			return list;
		}public static List<DekiemtraEntity> GetByFK_iNguoicapnhatID(Int64 FK_iNguoicapnhatID)
		{
			string cmdName = "spDekiemtra_GetByFK_FK_iNguoicapnhatID";
			SqlParameter p = new SqlParameter("@FK_iNguoicapnhatID",FK_iNguoicapnhatID);
			List<DekiemtraEntity> list = GetList(cmdName, p);
			return list;
		}public static List<DekiemtraEntity> GetByFK_iHinhthuckiemtraID(Int16 FK_iHinhthuckiemtraID)
		{
			string cmdName = "spDekiemtra_GetByFK_FK_iHinhthuckiemtraID";
			SqlParameter p = new SqlParameter("@FK_iHinhthuckiemtraID",FK_iHinhthuckiemtraID);
			List<DekiemtraEntity> list = GetList(cmdName, p);
			return list;
		}
        public static int Add(DekiemtraEntity entity)
        {
            string cmdName = "spDekiemtra_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(DekiemtraEntity entity)
        {
            string cmdName = "spDekiemtra_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iDekiemtraID)
        {
            string cmdName = "spDekiemtra_Delete";
            SqlParameter p = new SqlParameter("@PK_iDekiemtraID", PK_iDekiemtraID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(DekiemtraEntity entity)
        {
            SqlParameter[] p = new SqlParameter[8];
			p[0] = new SqlParameter("@PK_iDekiemtraID", entity.PK_iDekiemtraID);
			p[1] = new SqlParameter("@sTendekiemtra", entity.sTendekiemtra);
			p[2] = new SqlParameter("@sGhichu", entity.sGhichu);
			p[3] = new SqlParameter("@dNgaytao", entity.dNgaytao);
			p[4] = new SqlParameter("@dNgaycapnhat", entity.dNgaycapnhat);
			p[5] = new SqlParameter("@FK_iNguoitaoID", entity.FK_iNguoitaoID);
			p[6] = new SqlParameter("@FK_iNguoicapnhatID", entity.FK_iNguoicapnhatID);
			p[7] = new SqlParameter("@FK_iHinhthuckiemtraID", entity.FK_iHinhthuckiemtraID);
            return p;
        }
        #endregion
       
    }
}